package stats;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentLinkedQueue;

public class LinkedQueueStatsService implements IStatsService
{
	private ConcurrentLinkedQueue<String>	queue	= new ConcurrentLinkedQueue<String>();

	public void notify ( String key )
	{
		queue.add(key);
	}

	public Map<String, Number> getStats ( )
	{
		Map<String, Number> copy = new HashMap<String, Number>();
		String key;
		while ( ( key = queue.poll() ) != null)
		{
			Number value = copy.get(key);
			value = value == null ? 1 : value.longValue() + 1;
			copy.put(key, value);
		}
		return copy;
	}

	public void stop ( )
	{
	// TODO Auto-generated method stub

	}
}
